package com.prs.crm.action.oa;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.annotation.Clew;
import com.prs.crm.domain.oa.PredefineFlow;
import com.prs.crm.service.oa.PredefineFlowService;
/**
 * @author YangHao
 * @E-Mail:450098606@qq.com
 * @qq:450098606
 * @version 创建时间：2012-5-7 10:51:41 预定义流程
 */
public class PredefineFlowAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private PredefineFlow predefineFlow;
	private PredefineFlowService predefineFlowService;
	private PaginationSupport pagination;
	private Integer[] ids;
	public PredefineFlow getPredefineFlow() {
		return predefineFlow;
	}
	public void setPredefineFlow(PredefineFlow predefineFlow) {
		this.predefineFlow = predefineFlow;
	}
	public PredefineFlowService getPredefineFlowService() {
		return predefineFlowService;
	}
	public void setPredefineFlowService(PredefineFlowService predefineFlowService) {
		this.predefineFlowService = predefineFlowService;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	@Action("listPredefineFlow")
	public String listPredefineFlow(){
		DetachedCriteria crireria=this.getPaginationHelper().createQuery(PredefineFlow.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getPredefineFlowService().listByPage(crireria, pagination));
		return SUCCESS;
	}
	@Action("editPredefineFlow")
	public String editPredefineFloe(){
		return SUCCESS;
	}
	@Clew(results = { "success", "none" })
	@Action(value = "savePredefineFlow", results = {
			@Result(name = "success", type = "redirect", location = "listPredefineFlow"),
			@Result(name = "error", type = "chain", location = "editPredefineFlow"),
		 })
	public String savePredefineFlow(){
		this.getPredefineFlowService().save(predefineFlow);
		this.setPrompt("添加成功！");
		return SUCCESS;
	}
	
	@Action(value = "removePredefineFlow", results = {
			@Result(name = "success", type = "redirect", location = "listPredefineFlow"),
			@Result(name = "error", type = "chain", location = "listPredefineFlow"), })
	public String removePredefineFlow(){
		if (ids==null) {
			this.addActionError("请选择一行进行操作！");
			return ERROR;
		}
		this.getPredefineFlowService().batchRemove(ids);
		return SUCCESS;
	}
}
